home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
local
/
uiUsers.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
22KB
|
531 lines
<?php
/**
* User Interface Users tab
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 2.0.0
*/
/**
* @desc Display user left control
*
* @param WUserConfig $user
* @param boolean $sel: true if selected
*/
function uiUsersControl($user,$sel){
$id=$user->id();
// Icon
$o='<div class="adminUserIcon" style="float:left"><img alt="icon" src="/gfx/icons/'.$user->getVar('icon').'" id="uiUserBlockIcon'.$id.'" style="height:55;width:55;visibility:hidden" onload="fade(this)"></div>';
// Name
$o.='<div class="uiUserBlockName" id="uiUserBlockName'.$id.'">'.str_replace('<','<',cfUTF8Encode($user->getVar('name'))).'</div>';
//Admin
if($user->isAdministrator()) $o.='<div class="uiUserBlockAdmin">'.cfCaption('userAdministrator').'</div>';
// Up
$o.=outImage(outIcon('up'),"javascript:uiUserBlockUp('".$id."')",'id="up_'.$id.'"','position:absolute;top:5px;right:5px');
// Down
$o.=outImage(outIcon('down'),"javascript:uiUserBlockDown('".$id."')",'id="down_'.$id.'"','position:absolute;top:15px;right:5px');
// Delete
if(!$user->isAdministrator()) $o.=outImage(outIcon('del'),false,'id="del_'.$id.'" onclick="uiUserDelete(\''.$id.'\')" '.outToolTip('javascript:uiUsersDeleteTooltip'),'position:absolute;bottom:5px;cursor:pointer;left:70px;'.(($sel)?'':'display:none'));
// Activate(d)
$o.='<div style="position:absolute;right:5px;bottom:5px">'.cfCaption('genActivated').'<input type="checkbox" '.(($user->getVar('activated'))?'checked="checked"':'').' onclick="uiUserActivated(\''.$id.'\')" id="activated_'.$id.'" style="vertical-align:middle"></div>';
return outBlockItem('uiUsersRes',$o,'id="userBlock_'.$id.'" onmouseup="uiUserSelect(\''.$id.'\')"','position:absolute;padding-bottom:5px;width:200px;display:block;overflow:hidden;text-overflow:ellipsis;margin:0;margin-bottom:3px;text-align:left',false,(($sel)?'sel':'unsel'));
}
/**
* @desc Return HTML code for given user configuration page
*
* @param WUserConfig $user
* @return string
*/
function uiUsersUserConfig($uc){
$o='';
require_once(INCLUDE_DIR.'resourceConfigFunctions.php');
// Send invitation button
$o.=outButton75(outImage(outIcon('mailOut')),"uiUserSendInvitation('".$uc->id()."')",'style="float:right"',cfCaption('userInvite'));
/**
* 1st block: name, groupType, hidden, icon
*/
$o.='<table class="uiUsersGroup" style="width:468px"><tr>';
// Group picture
$o.='<td style="width:48px;text-align:center"><img src="'.outIcon('uiUsersGroup').'"></td>';
$o.='<td style="width:180px">';
// Name
$o.='<div class="title" style="margin-bottom:0.5em">'.cfCaption('genName').'</div>';
$o.='<input class="textInput uiUsersNameInput" value="'.str_replace('"','"',cfUTF8Encode($uc->getVar('name'))).'" onkeyup="uiUsersDataNameChanged(this)" onchange="uiUsersDataNameChanged(this)" id="uiUsersDataName"><br>';
$o.='</td><td style="vertical-align:middle">';
// Group type
$o.='<select '.outToolTip(cfCaption('groupTypeDesc')).' class="textInput" type="select" onchange="uiUserUpdate(\'accountType\',this.value)">';
$o.='<option value="singleUser"'.(($uc->getVar('accountType')=='singleUser')?' selected':'').'>'.cfCaption('userAccountTypeSingleUser').'</option>';
$o.='<option value="named"'.(($uc->getVar('accountType')=='named')?' selected':'').'>'.cfCaption('userAccountTypeNamed').'</option>';
$o.='<option value="anonymous"'.(($uc->getVar('accountType')=='anonymous')?' selected':'').'>'.cfCaption('userAccountTypeAnonymous').'</option>';
$o.='</select><br><br>';
// Hidden group
$o.='<div '.outToolTip(cfCaption('hiddenGroupDesc')).'><input type="checkbox" '.(($uc->getVar('hidden'))?'checked="checked"':'').' style="vertical-align:middle;margin-right:0.5em" onclick="uiUserUpdate(\'hidden\',this.checked)">'.cfCaption('userHidden').'</div>';
// Icon
$o.='</td><td style="width:69px;text-align:right">';
$o.='<div class="uiUsersIcon"><img src="/gfx/icons/'.$uc->getVar('icon').'" onclick="uiUserChangeIcon()" id="selUserIcon" style="width:60px;height:60px"></div>';
$o.='</td></tr></table>';
/**
* User not activated warning
*/
$o.='<div id="uiUsersActWarning" class="extendedWarning"'.(($uc->getVar('activated'))?' style="display:none"':'').'>'.outImageIcon('warning').cfCaption('accountNotActivated').'</div>';
/**
* 2nd block: Password / security
*/
$o.='<table class="uiUsersGroup frame2"><tr>';
// Lock picture
$o.='<td style="width:48px;text-align:center;vertical-align:top"><img src="'.outIcon('uiUsersLock').'" style="margin-top:16px"></td>';
$o.='<td style="white-space:nowrap;position:relative">';
// Authentication method
$o.='<b>'.cfCaption('userAuthentification').'</b><br>';
$o.='<select name="passwordSelect" class="textInput" type="select" onchange="uiUsersDataAuthenticationChanged(this.value)" style="width:140px;margin-right:0.5em;vertical-align:middle">';
$o.='<option value="password"'.(($uc->getVar('authenticationMethod')=='password')?' selected':'').' id="uiUsersDataAuthenticationNA">'.cfCaption('genPassword').'</option>';
if(!$uc->isAdministrator())
$o.='<option value="noAuthentication"'.(($uc->getVar('authenticationMethod')=='noAuthentication')?' selected':'').'>'.cfCaption('userAuthenticationNoAuthentication').'</option>';
$o.='</select>';
// Password
$o.=outBt(cfCaption('genPassword'),outIcon('pwdS'),'javascript:uiUsersPwdSet()','uiUsersPwdBt',false,'style="margin-right:1em;vertical-align:middle"','up',90);
// Hint
$o.='<span style="vertical-align:middle" '.outToolTip(str_replace('"','"',cfCaption('logHintHelp'))).'>'.cfCaption('logHint');
$o.='<input id="uiUsersDataHint" class="textInput" value="'.str_replace('"','"',cfUTF8Encode($uc->getVar('hint'))).'" onkeyup="uiUsersDataHintChanged(this)" onchange="uiUsersDataHintChanged(this)"'.(($uc->getVar('authenticationMethod')=='noAuthentication')?' disabled':'').' style="width:120px;vertical-align:middle;margin-left:0.5em">';
$o.='</span>';
$o.='<br><br> ';
/**
* Advanced security config
*/
$showAdvancedConfig=cfGGetVar('uiUsersAdvancedConfig');
// Advanced config toggle
$o.='<div class="advancedConfigToggleBt" id="advancedConfigUnfoldBt" onclick="uiUsersToggleAdvancedConfig()" style="bottom:0px;top:auto">';
$o.=cfCaption('configAdvanced');
$o.=outimage(outIcon('advancedConfigUnfold'),false,'id="advancedConfigUnfoldIco"','vertical-align:middle;'.(($showAdvancedConfig)?'':'display:none'));
$o.=outimage(outIcon('advancedConfigFold'),false,'id="advancedConfigFoldIco"','vertical-align:middle;'.((!$showAdvancedConfig)?'':'display:none'));
$o.='</div>';
$o.='<div id="advancedConfigDiv" '.(($showAdvancedConfig)?'':'style="display:none"').'>';
// IP restrictions
$IPIcon=($uc->getVar('IPFilter') && $uc->getVar('IPFilter')!=='no')?outIcon('warning'):outIcon('ahead');
$o.=outBt(cfCaption('configIPFilter'),$IPIcon,'javascript:uiUsersIPSet()','uiUsersIPBt',false,'style="margin-right:1em;vertical-align:middle"','up',90);
// Max users
$o.='<span style="vertical-align:middle;margin-right:0.5em">'.cfCaption('loginMaxUsers').'</span>';
$o.='<select class="textInput" type="select" onchange="uiUserUpdate(\'maxSimultaneousUsers\',this.value)" style="margin-right:0.5em;vertical-align:middle;width:60px">';
for($i=0;$i<11;$i++){
if($i==1 || $uc->getVar('accountType')!='singleUser')
$o.='<option value="'.(int)$i.'" '.(($i==$uc->getVar('maxSimultaneousUsers'))?'selected':'').'>'.(($i)?$i:cfCaption('genUnlimited')).'</option>';
}
$o.='</select>';
// Max download
$o.='<span style="vertical-align:middle;margin-right:0.5em;margin-left:3em">'.cfCaption('explorerDlLimit').'</span>';
$o.='<input class="textInput" value="'.(int)($uc->getVar('downloadSpeedLimit')).'" onkeyup="uiUsersDataDLLimitChanged(this)" onchange="uiUsersDataDLLimitChanged(this)" style="width:30px;vertical-align:middle;text-align:right">';
$o.='<span style="vertical-align:middle;margin-left:0.5em">'.cfCaption('explorerKBPS').'</span>';
$o.='<br><br> </div>';
$o.='</td></tr></table>';
/**
* 3rd block: theme, sound
*/
$o.='<table class="uiUsersGroup"><tr>';
// Theme picture
$o.='<td style="width:48px;text-align:center;vertical-align:middle">'.outImage(outIcon('theme24')).'</td>';
$o.='<td style="padding-top:5px;padding-bottom:5px">';
// Theme selection button
$o.='<span style="margin-right:2em;vertical-align:middle">'.cfCaption('configDefaultTheme').'</span>';
$o.=outButton(cfCaption('genTheme').' ('.(($uc->getVar('theme'))?ucfirst(cfUTF8Encode($uc->getVar('theme'))):cfCaption('genDefault')).')','javascript:uiUsersSelectTheme()',outIcon('theme'),false,'uiUsersSelectThemeBt','style="vertical-align:middle"');
// Audio profile
$o.='<span style="margin-left:2em;margin-right:0.5em">'.cfCaption('userAudioProfile').'</span>';
$o.='<select class="textInput" type="select" onchange="uiUserUpdate(\'audioProfile\',this.value)" style="vertical-align:middle">';
$o.='<option value="noSound"'.(($uc->getVar('audioProfile')=='no')?' selected':'').'>'.cfCaption('userAudioNoSound').'</option>';
foreach (cfGlob(cfAppDocRoot().'/snd/*') as $cfn) if(is_dir($cfn)){
$o.='<option value="'.basename($cfn).'"'.(($uc->getVar('audioProfile')==basename($cfn))?' selected':'').'>'.cfUTF8Encode(basename($cfn)).'</option>';
}
$o.='</select>';
$o.='</td></tr></table>';
/**
* 4th block: sticky notes
*/
$o.='<table class="uiUsersGroup frame2"><tr>';
// Sticky notes picture
$o.='<td style="width:48px;text-align:center"><img src="'.outIcon('sNotes24').'"></td>';
$o.='<td style="padding-top:5px;padding-bottom:5px">';
$o.='<b style="margin-right:2em;vertical-align:middle">'.cfCaption('sNotes').'</b>';
// Sticy notes access
$o.='<select class="textInput" type="select" onchange="uiUserUpdate(\'sNotes\',this.value)" style="vertical-align:middle">';
$o.='<option value="0"'.(($uc->getVar('sNotes')==0)?' selected':'').'>'.cfCaption('genNo').'</option>';
$o.='<option value="1"'.(($uc->getVar('sNotes')==1)?' selected':'').'>'.cfCaption('genShow').'</option>';
$o.='<option value="2"'.(($uc->getVar('sNotes')==2)?' selected':'').'>'.cfCaption('genShow').' / '.cfCaption('adminResourceCreate').'</option>';
$o.='<option value="3"'.(($uc->getVar('sNotes')==3)?' selected':'').'>'.cfCaption('genShow').' / '.cfCaption('adminResourceCreate').' / '.cfCaption('genDelete').'</option>';
$o.='</select><br>';
$o.='</td></tr></table>';
/**
* 5th block: bound resources
*/
$o.='<table class="uiUsersGroup uiUsersResGroup" id="linkedResourcesFrame"><tr style="height:32px">';
// Resources picture
$o.='<td style="width:48px;text-align:center;vertical-align:top"><img src="'.outIcon('resources24').'"></td>';
$o.='<td style="white-space:nowrap;position:relative;vertical-align:top">';
// Add resource button
$o.='<div style="float:right">'.outButton(cfCaption('genAdd'),'javascript:uiUsersAddResource()',outIcon('add2')).'</div>';
// User's resources title
$o.='<div class="title">'.cfCaption('userResources').'</div>';
// Overflow node
$o.='</td></tr><tr><td colspan="2" style="vertical-align:top;position:relative"><div style="overflow:auto;height:95%" id="linkedResourcesScroll">';
// Bound resources
if($uc->getResources())
foreach ($uc->getResources() as $rid=>$filename) $o.=rcResourceBlock($rid,$uc);
else
$o.='<center><div style="position:relative;top:10%;width:240px;margin-left:auto;margin-right:auto"><div class="frame3" style="padding:10px">'.outImage(outIcon('info32'),false,false,'margin-bottom:5px').'<br>'.cfCaption('genNoDefinedResource').'</div></div></center>';
$o.='</div>';
if(cfBGetVar('png')) $o.='<div class="uiUsersResMask"></div><div class="uiUsersResMask bottom"></div>';
$o.='</td></tr></table>';
return $o;
}
if(!cfIsInApp()) die();
require_once(INCLUDE_DIR.'outputFunctions.php');
// Get users
$users=cfUsersConfigs();
/**
***************************************************************************************************************************
* Process Async command
***************************************************************************************************************************
*/
if(cfIsAsync()){
cfAsyncHeader();
// Change users order
if(isset($_POST['userOrder'])){
$no=array();
foreach (explode(',',$_POST['userOrder']) as $uid) if(isset($users[$uid])) $no[]=$users[$uid]->filename();
cfGUpdateVar('users',implode(',',$no));
}
// Change advanced config display
if(isset($_POST['userShowAdvancedConfig'])){
cfGUpdateVar('uiUsersAdvancedConfig',(int)$_POST['userShowAdvancedConfig']);
}
/**
* Create user
*/
if(isset($_POST['userCreate'])){
$name=cfUTF8Decode($_POST['userCreate'],true,false,false);
$pwd='';
if(strpos($name,'*weezoSep*')) list($name,$pwd)=explode('*weezoSep*',$name);
$uc=new WUserConfig();
$uc->setVar('name',$name);
if($pwd){
$uc->setVar('authenticationMethod','password');
$uc->setVar('password',md5($pwd));
}
else{
$uc->setVar('authenticationMethod','noAuthentication');
}
// Pick a random icon
$icons=cfGlob(cfAppDocRoot().'/gfx/icons/*.jpg');
$uc->setVar('icon',basename($icons[rand(0,count($icons))]));
// Save user
$uc->save();
// Select created user
cfGUpdateVar('uiUsersSelectedId',$uc->id());
// Add new user block
echo cfAsyncXMLInnerHTMLbyId(uiUsersControl($uc,true),'uiUsersBlocksDiv',true);
// Select user
echo cfAsyncXMLJSaction('users[users.length]="'.$uc->id().'";uiUserResetBlocks();uiUserScrollTo("'.$uc->id().'");uiUserSelect("'.$uc->id().'");');
// Reload page
echo cfAsyncXMLJSaction('wl.goURL()');
}
/**
* Delete user
*/
if(isset($_POST['userDelete']) && isset($users[$_POST['userDelete']])){
$uc=$users[$_POST['userDelete']];
$uc->del();
echo cfAsyncXMLJSaction('wl.goURL()');
}
// Verify passed user id exists, or terminate requests with no specific user Id
if(!isset($_POST['userId']) || !isset($users[$_POST['userId']])) die(cfAsyncFooter());
$uc=$users[$_POST['userId']];
// Select an user
if(isset($_POST['userSelect'])){
cfGUpdateVar('uiUsersSelectedId',$_POST['userId']);
$refreshUserConfig=true;
echo cfAsyncXMLJSaction('uiUserFile="'.$uc->filename().'"');
}
// Remove a resource from an user
if(isset($_POST['removeResource'])){
$uc->removeResource($_POST['removeResource']);
$uc->save();
$refreshUserConfig=true;
}
// Reorder user's resources
if(isset($_POST['userResMoveUp']) && isset($_POST['userResMoveDown'])){
$prev=$uc->swapResources($_POST['userResMoveUp'],$_POST['userResMoveDown']);
$uc->save();
$refreshUserConfig=true;
}
// Add resource(s)
if(isset($_POST['userAddResources'])){
foreach (explode('/',$_POST['userAddResources']) as $rid) $uc->addResource($rid);
$uc->save();
$refreshUserConfig=true;
}
// Create new resource
if(isset($_POST['userCreateNewResource'])){
cfServerSendCmd('createNewResource');
}
/**
* User config modification
*/
if(isset($_POST['updateData']) && isset($_POST['updateValue']) && isset($_POST['userId']) && isset($uc)){
$ok=0;
$k=$_POST['updateData'];
$v=$_POST['updateValue'];
switch ($k){
case 'name':
$v=cfUTF8Decode($v,true,false,false,30);
$ok=1;
break;
case 'icon':
if(file_exists(cfAppDocRoot().'/gfx/icons/'.$v)) $ok=1;
break;
case 'accountType':
if($v=='singleUser' || $v=='named' || $v=='anonymous') {
$ok=1;
if($v=='singleUser') $uc->setVar('maxSimultaneousUsers',1);
elseif ($uc->getVar('maxSimultaneousUsers')==1) $uc->setVar('maxSimultaneousUsers',0);
$refreshUserConfig=1;
}
break;
case 'hidden':
case 'activated':
$v=($v=='true')?true:false;
$ok=1;
break;
case 'authenticationMethod':
if($v=='noAuthentication' && !$uc->isAdministrator()) $ok=1;
break;
case 'password':
$v=md5(cfUTF8Decode($v,true,false,false));
$uc->setVar('authenticationMethod','password');
$ok=1;
break;
case 'hint':
$v=cfUTF8Decode($v,true,false,false,260);
$ok=1;
break;
case 'maxSimultaneousUsers':
$v=(int)$v;
if($v>=0 && $v<11) $ok=1;
break;
case 'downloadSpeedLimit':
$v=(int)$v;
if($v>=0) $ok=1;
break;
case 'audioProfile':
if($v=="no" || is_dir(cfAppDocRoot().'/snd/'.str_replace('/','',$v))) $ok=1;
if($ok && $v!='no') cfServerSendCmd('userModifiedAudioProfile',array('newProfile'=>$v));
break;
case 'sNotes':
$v=(int)$v;
if($v>=0 && $v<4) $ok=1;
break;
case 'theme':
// option already saved by theme form => just redraw
$refreshUserConfig=1;
break;
case 'displayResourceAtLogin':
$ok=1;
$refreshUserConfig=1;
break;
}
if($ok){
$uc->setVar($k,$v);
$uc->save();
}
}
if(isset($_POST['userSendInvitation']) && isset($_POST['userId'])){
//cfDbg($_POST['userId']);
$regInfo=cfIsRegistered();
// If user is registered, call mail application
if(isset($regInfo['regName'])){
$subject=str_replace('"',"''",APPLICATION_NAME.' - '.$uc->getVar('name'));
$body=cfCaption('genAdress',DNS_SITE.'/'.$regInfo['regName'].'?user='.$uc->getVar('name'));
$body.=' , '.cfCaption('genGroup').cfCaption('genSeparator').$uc->getVar('name');
if($uc->getVar('authenticationMethod')=='password') $body.=' , '.cfCaption('genPassword').cfCaption('genSeparator').'XXXX';
$body=str_replace('"',"''",$body);
cfServerSendCommand('openMail body="'.$body.'" subject="'.$subject.'"');
}
// else just display error message
else{
$msgbox='dB=new dialogBox({"text":"'.addslashes(cfCaption('registrationNeeded')).'","title":"'.cfCaption('alertWarningTitle').'","icon":"'.outIcon('info2').'","mask":1,"fade":1,"buttons":{"cancel":"'.cfCaption('genCancel').'"}});dB.show()';
echo cfAsyncJSaction($msgbox);
}
}
if(isset($refreshUserConfig)) {
echo cfAsyncXMLJSaction('uiUsersResScrollGet()');
echo cfAsyncXMLInnerHTMLbyId(uiUsersUserConfig($uc),'userFrame');
echo cfAsyncXMLJSaction('winResized()');
echo cfAsyncXMLJSaction('uiUsersResScrollSet()');
}
die(cfAsyncFooter());
}
/**
***************************************************************************************************************************
* Insert page HEADER
***************************************************************************************************************************
*/
cfInsertHEAD(false);
echo cfScriptLink('winClient.js');
?>
<style type="text/css">
</style>
</head>
<body style="padding:0px;margin:0px;overflow:hidden">
<?php
echo cfScriptLink('wz_dragdrop.js');
/**
***************************************************************************************************************************
* Users list frame
***************************************************************************************************************************
*/
?>
<div id="usersListFrame" class="frame2 uiLeftFrame" style="float:left;width:210px">
<div class="uiTabTitle"><?php echo cfCaption('genGroups');?></div>
<center>
<?php
// New user button
echo outBt('<b style="font-weight:bold">'.cfCaption('userNewUser').'</b>',outIcon('new'),"javascript:uiUserCreate()",false,false,'style="margin-left:0;margin-right:0"','up',170);
?>
<div id="uiUsersBlocksDiv" style="position:relative;overflow:auto;width:221px;height:375px;margin-left:auto;margin-right:auto;margin-top:1em;text-align:left">
<?php
// unique ID of selected user
if(isset($_GET['userSelectedId'])) cfGUpdateVar('uiUsersSelectedId',$_GET['userSelectedId']);
$uiUsersSelectedId=cfGGetVar('uiUsersSelectedId');
if(!isset($users[$uiUsersSelectedId])){
foreach ($users as $id=>$user){
$uiUsersSelectedId=$id;
cfGUpdateVar('uiUsersSelectedId',$id);
break;
}
}
// Display users controls
foreach ($users as $id=>$user){
echo uiUsersControl($user,($id==$uiUsersSelectedId));
}
?>
</center>
</div><?php // eo overflow frame ?>
</div><?php // eo frame2 uiLeftFrame ?>
<?php
/**
***************************************************************************************************************************
* Configured user frame
***************************************************************************************************************************
*/
?>
<div id="userFrame" class="frame1" style="display:block;margin:0px;height:473px;padding:7px;margin-left:0px">
<?php
echo uiUsersUserConfig($users[$uiUsersSelectedId]);
?>
</div>
<?php
/**
* Scripts
*/
?>
<script type="text/javascript">
var inApp="<?php echo (int)cfIsInApp(); ?>";
var uiUserSelected="<?php echo $uiUsersSelectedId; ?>";
var uiShowAdvancedConfig="<?php echo (int)cfGGetVar('uiUsersAdvancedConfig'); ?>";
var users=[<?php $nb=0;foreach ($users as $id=>$user) echo (($nb++==0)?'':',').'"'.$id.'"'; ?>];
var uiUserFile="<?php echo $users[$uiUsersSelectedId]->filename()?>";
var delConfCapt="<?php echo addslashes(cfCaption('userConfirmDelete'));?>";
var uiUsersDeleteTooltip="<?php echo addslashes(outImageIcon('warning').cfCaption('genDelete'));?>";
</script>
<?php
echo cfScriptLink('uiUsers.js');
echo cfDragRegisterItems('');
?>
</body>